Skip to content

Convert paragraph content to markdown#506

Closed
gurkerl83 wants to merge 2 commits intocode-hike:nextfrom
gurkerl83:Section-Wise-Markdown-Export
Closed

Convert paragraph content to markdown#506
gurkerl83 wants to merge 2 commits intocode-hike:nextfrom
gurkerl83:Section-Wise-Markdown-Export

Conversation

@gurkerl83
Copy link

  • Introduce isMarkdownEnabled helper function to detect whether an MDX element sets markdownEnabled (either via shorthand or boolean expression).
  • Convert paragraph content to Markdown if markdownEnabled is set, accumulating the result in a new node.markdown field.
  • Use toMarkdown from mdast-util-to-markdown to transform AST nodes to Markdown.

- Introduce `isMarkdownEnabled` helper function to detect whether an MDX element sets `markdownEnabled` (either via shorthand or boolean expression).
- Convert paragraph content to Markdown if `markdownEnabled` is set, accumulating the result in a new `node.markdown` field.
- Use `toMarkdown` from `mdast-util-to-markdown` to transform AST nodes to Markdown.
@vercel
Copy link

vercel bot commented Mar 31, 2025

@gurkerl83 is attempting to deploy a commit to the codehike Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 31, 2025

Try codehike from this pull request in your project with:

npm i https://pkg.pr.new/codehike@506

@github-actions github-actions bot added the changeset PR including changesets label Apr 30, 2025
gurkerl83 added a commit to gurkerl83/codehike that referenced this pull request Feb 18, 2026
Context:
- This PR is based on `next`.
- Prior work exists in code-hike#506 (not merged into `next`), and is referenced here as the previous approach.

Top-level detail:
- Previous approach (PR code-hike#506) generated `__hike.markdown` from AST serialization, so upstream remark AST mutations were reflected but source fidelity was not guaranteed.
- This caused round-trip drift (formatting/line endings/GFM layout normalization).
- This change generates `__hike.markdown` from original source offsets, prioritizing source-faithful output and side effect free plugin results.

Additional changes:
- Thread original source through the remark transform path into section serialization.
- Compute markdown only from section content paragraphs using node offsets.
- Preserve flow-level `<br />` spacing semantics:
  - leading breaks before the first paragraph,
  - one baseline separator newline plus extra newlines for intermediate `<br />`,
  - trailing breaks after the last paragraph.
- Keep markdown export opt-in via `markdownEnabled` (attribute behavior unchanged).
- Remove the extra markdown serialization dependency introduced in the previous approach.
- Add focused tests for:
  - source-preserving markdown capture,
  - behavior when `markdownEnabled` is not set,
  - `<br />` spacing behavior.
@gurkerl83 gurkerl83 closed this Feb 18, 2026
@gurkerl83
Copy link
Author

Closing in favor of #528

@gurkerl83 gurkerl83 deleted the Section-Wise-Markdown-Export branch February 19, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changeset PR including changesets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments